Extension { #name : 'ClyMethodCodeEditorToolMorph' }

{ #category : '*Calypso-SystemTools-OldToolCompatibillity' }
ClyMethodCodeEditorToolMorph >> findFirstOccurrenceOf: searchedString in: textToSearchIn [
	"Return the first index of aString in textToSearchIn "
	| firstIndex |
	firstIndex := textToSearchIn findString: searchedString startingAt: 1.
	[ (firstIndex > 1) and: [ (textToSearchIn at: (firstIndex - 1)) isAlphaNumeric ] ]
		whileTrue: [
			firstIndex := textToSearchIn findString: searchedString startingAt: firstIndex +1 ].

	^ firstIndex
]

{ #category : '*Calypso-SystemTools-OldToolCompatibillity' }
ClyMethodCodeEditorToolMorph >> findString: searchedString asSelectorIn: aString [
	"Return the interval that corresponds to the portion of aString "
	"This method takes care of finding complete match to searchedString. "
	| string interval firstIndex |

	searchedString ifNil: [ ^ 0 to: 0 ].
	aString isEmptyOrNil ifTrue: [ ^0 to: 0 ].
	string := aString asString.
	interval := 0 to: 0.

	(searchedString includes: $:)
		ifTrue: [ | list |
			list := searchedString substrings: ':'.
			list size = 1
				ifTrue: [" binary selector "
					firstIndex := self findFirstOccurrenceOf: searchedString in: string.
					firstIndex isZero
						ifFalse: [ interval := firstIndex to: (firstIndex+searchedString size-1) ] ]

				ifFalse: [
					| lastIndex |
					firstIndex := self findFirstOccurrenceOf: list first, ':' in: string.
					firstIndex >0 ifTrue: [
								lastIndex := string findString: list last,':' startingAt: firstIndex+ (list first size -1).
								interval := firstIndex to: (lastIndex + list last size) ] ] ]
		ifFalse: [
			" unary selector "
			firstIndex := self findFirstOccurrenceOf: searchedString in: string.
			 firstIndex > 0
						ifTrue: [ interval := firstIndex to: (firstIndex+searchedString size - 1) ] ].
	^ interval
]

{ #category : '*Calypso-SystemTools-OldToolCompatibillity' }
ClyMethodCodeEditorToolMorph >> selectStringAsInMessageBrowser: criteriaString [

	| interval |
	interval := (self findAnySelectorInSourceCode: {criteriaString})
			ifEmpty: [ self findString: criteriaString asSelectorIn: self pendingText].
	textMorph setSelection: interval
]
